﻿using System;
using System.Collections.Generic;
using System.Text;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.ZLog;

namespace UtilZ.Dotnet.Ex.Model
{
    /// <summary>
    /// 序列器接口
    /// </summary>
    public class DefaultSerializeProvider : SerializeProviderAbs
    {
        private static DefaultSerializeProvider _default;
        /// <summary>
        /// 获取默认序列化器
        /// </summary>
        public static DefaultSerializeProvider Default
        {
            get { return _default; }
        }

        static DefaultSerializeProvider()
        {
            _default = new DefaultSerializeProvider();
        }



        /// <summary>
        /// 构造函数
        /// </summary>
        public DefaultSerializeProvider()
            : base()
        {

        }


        /// <summary>
        /// 获取序列器对象
        /// </summary>
        /// <param name="serializeType">序列化类型</param>
        /// <returns>序列化器</returns>
        protected override ISerializer PrimitiveGetSerializer(string serializeType)
        {
            ISerializer serializer;
            switch (serializeType)
            {
                case SerializeTypes.JSON:
                    serializer = new DefaultJsonSerializer();
                    break;
                case SerializeTypes.XML:
                    serializer = new DefaultXmlSerializer();
                    break;
                default:
                    throw new NotSupportedException($"实体:{this.GetType().FullName}的序列化类型:{serializeType}不支持");
            }

            return serializer;
        }

    }
}
